<?php
// $Id: node.tpl.php,v 1.4 2008/09/15 08:11:49 johnalbin Exp $

/**
 * @file node.tpl.php
 *
 * Theme implementation to display a node.
 *
 * Available variables:
 * - $title: the (sanitized) title of the node.
 * - $content: Node body or teaser depending on $teaser flag.
 * - $picture: The authors picture of the node output from
 *   theme_user_picture().
 * - $date: Formatted creation date (use $created to reformat with
 *   format_date()).
 * - $links: Themed links like "Read more", "Add new comment", etc. output
 *   from theme_links().
 * - $name: Themed username of node author output from theme_user().
 * - $node_url: Direct url of the current node.
 * - $terms: the themed list of taxonomy term links output from theme_links().
 * - $submitted: themed submission information output from
 *   theme_node_submitted().
 *
 * Other variables:
 * - $node: Full node object. Contains data that may not be safe.
 * - $type: Node type, i.e. story, page, blog, etc.
 * - $comment_count: Number of comments attached to the node.
 * - $uid: User ID of the node author.
 * - $created: Time the node was published formatted in Unix timestamp.
 * - $zebra: Outputs either "even" or "odd". Useful for zebra striping in
 *   teaser listings.
 * - $id: Position of the node. Increments each time it's output.
 *
 * Node status variables:
 * - $teaser: Flag for the teaser state.
 * - $page: Flag for the full page state.
 * - $promote: Flag for front page promotion state.
 * - $sticky: Flags for sticky post setting.
 * - $status: Flag for published status.
 * - $comment: State of comment settings for the node.
 * - $readmore: Flags true if the teaser content of the node cannot hold the
 *   main body content.
 * - $is_front: Flags true when presented in the front page.
 * - $logged_in: Flags true when the current user is a logged-in member.
 * - $is_admin: Flags true when the current user is an administrator.
 *
 * @see template_preprocess()
 * @see template_preprocess_node()
 */

$base_path = base_path();

?>

<?php if ($page) { ?>

	<h1><?php print $title; ?></h1>
	
	<p class="summary"><?php print $field_summary[0]['view']; ?></p>
	
	<p class="description"><?php print $field_description[0]['view']; ?></p>
	
	<?php 
	if (($cache = cache_get('demonz_newsletter_xml')) && !empty($cache->data)) {
    	$xmlfeed = $cache->data;
    } else {
    	$xmlfeed = file_get_contents('http://www.d-news.com.au/rss-kings.php?List=62&Fetch=25');
    	cache_set('demonz_newsletter_xml', $xmlfeed, 'cache', CACHE_TEMPORARY);
    }
	
	if ($xmlfeed) {
		require_once('parseXML.php');
		$xml2assoc = new Xml2Assoc();
		$xmlarray = $xml2assoc->parseString($xmlfeed);
	}
	?>
	
	<?php if ($xmlarray) { ?>
	<div class="newsletters">
		<div class="newsletter">
			<?php foreach ($xmlarray['rss'][0]['channel']['item'] as $newsletter) { ?>
			<h2><?php print $newsletter['title'][0]; ?></h2>
			<p class="summary"><?php print demonz_substr($newsletter['content'][0], 250); ?></p>
			<p class="read-more"><a href="<?php print $newsletter['link'][0]; ?>">Read more</a></p>
			<?php } //end foreach ($xmlarray['rss'][0]['channel']['item'] as $newsletter) ?>
		</div>
		<?php // print '<pre>'; print_r($xmlarray); print '</pre>'; ?>
	</div>
	<?php } //end if ($xmlarray) ?>
	
	<?php if (isset($field_image[0]['filepath'])) { ?>
	<div class="images">
		<h3>Images</h3>
		<ul>
			<?php foreach ($field_image as $image) { ?>
			<?php $zebra = ($zebra == 'odd') ? 'even' : 'odd'; ?>
			<li class="<?php print $zebra; ?>">
				<a class="lightbox image-set" rel="<?php print $title; ?>" href="<?php print $base_path; ?>sites/default/files/imagecache/image-large/<?php print $image['filepath']; ?>">
				<img src="<?php print $base_path; ?>sites/default/files/imagecache/image-medium/<?php print $image['filepath']; ?>" />
				</a>
			</li>
			<?php } //end foreach ($field_image as $image) ?>
		</ul>
	</div>
	<?php } //end if (isset($field_image[0]['filepath'])) ?>
	
	<?php if (isset($field_file[0]['filepath'])) { ?>
	<div class="files">
		<h3>Related file downloads</h3>
		<ul>
			<?php foreach ($field_file as $file) { ?>
			<?php $zebra = ($zebra == 'odd') ? 'even' : 'odd'; ?>
			<li class="<?php print $zebra; ?>"><a href="<?php print $base_path.$file['filepath']; ?>"><?php print $file['filename']; ?></a></li>
			<?php } //end foreach ($field_file as $file) ?>
		</ul>
	</div>
	<?php } //end if (isset($field_file[0]['filepath'])) ?>
	
	<?php if (isset($field_node[0]['view']) && !empty($field_node[0]['view'])) { ?>
	<div class="nodes">
		<h3>Related pages</h3>
		<ul>
			<?php foreach ($field_node as $rel_node) { ?>
			<?php $zebra = ($zebra == 'odd') ? 'even' : 'odd'; ?>
			<li class="<?php print $zebra; ?>"><?php print $rel_node['view']; ?></li>
			<?php } //end foreach ($field_node as $rel_node) ?>
		</ul>
	</div>
	<?php } //end if (isset($field_node[0]['view']) && !empty($field_node[0]['view'])) ?>
	
	<?php if (isset($field_link[0]['url']) && !empty($field_link[0]['url'])) { ?>
	<div class="links">
		<h3>External links</h3>
		<ul>
			<?php foreach ($field_link as $link) { ?>
			<?php $zebra = ($zebra == 'odd') ? 'even' : 'odd'; ?>
			<li class="<?php print $zebra; ?>"><?php print $link['view']; ?></li>
			<?php } //end foreach ($field_link as $link) ?>
		</ul>
	</div>
	<?php } //end if (isset($field_link[0]['url']) && !empty($field_link[0]['url'])) ?>
	
	<?php // print '<pre>'; print_r($node); print '</pre>'; ?>
	
	<?php if ($sitemap_child_nodes) { ?>
	<?php print $sitemap_child_nodes; ?>
	<?php } // end if ($sitemap_child_nodes) ?>

<?php } else if ($teaser) { ?>

	<div class="row">
		<div class="summary-image">
			<?php if (isset($field_image[0]['filepath'])) { ?>
			<img src="<?php print $base_path; ?>sites/default/files/imagecache/image-small/<?php print $field_image[0]['filepath']; ?>" />
			<?php } //end if (isset($field_image[0]['filepath'])) ?>
		</div>
		<h2><?php print $title; ?></h2>
		<p class="display-date"><?php if(isset($field_datetime[0]['view'])) print $field_datetime[0]['view']; ?></p>
		<p class="summary"><?php print $field_summary[0]['view']; ?></p>
		<p class="read-more"><a href="<?php print $base_path.$path; ?>">Read more</a></p>
	</div>

<?php } // end if (!$teaser) ?>



